#include "Types.h"

Bitboard RMasks[64];
Bitboard RMagics[64];
Bitboard* RAttacks[64];
Bitboard RShifts[64];

Bitboard BMasks[64];
Bitboard BMagics[64];
Bitboard* BAttacks[64];
int BShifts[64];

Bitboard SetMaskBB[65];
Bitboard ClearMaskBB[65];

Bitboard FileBB[8];
Bitboard RankBB[8];
Bitboard NeighboringFilesBB[8];
Bitboard ThisAndNeighboringFilesBB[8];
Bitboard InFrontBB[2][8];
Bitboard StepAttacksBB[16][64];
Bitboard BetweenBB[64][64];
Bitboard SquaresInFrontMask[2][64];
Bitboard PassedPawnMask[2][64];
Bitboard AttackSpanMask[2][64];

Bitboard PseudoAttacks[6][64];

//int BitCount8Bit[256];
//int SquareDistance[64][64];


inline unsigned rook_index(Square s, Bitboard occ) {
  Bitboard b = occ & RMasks[s];
  return unsigned(int(b) * int(RMagics[s]) ^ int(b >> 32) * int(RMagics[s] >> 32)) >> RShifts[s];
}

inline unsigned bishop_index(Square s, Bitboard occ) {
  Bitboard b = occ & BMasks[s];
  return unsigned(int(b) * int(BMagics[s]) ^ int(b >> 32) * int(BMagics[s] >> 32)) >> BShifts[s];
}

inline Bitboard bit_is_set(Bitboard b, Square s) {
  return b & SetMaskBB[s];
}

inline void set_bit(Bitboard* b, Square s) {
  *b |= SetMaskBB[s];
}

inline void clear_bit(Bitboard* b, Square s) {
  *b &= ClearMaskBB[s];
}

inline Bitboard rook_attacks_bb(Square s, Bitboard occ) {
  return RAttacks[s][rook_index(s, occ)];
}

inline Bitboard bishop_attacks_bb(Square s, Bitboard occ) {
  return BAttacks[s][bishop_index(s, occ)];
}

inline Bitboard queen_attacks_bb(Square s, Bitboard blockers) {
  return rook_attacks_bb(s, blockers) | bishop_attacks_bb(s, blockers);
}
